home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / CodeWarrior Lite / Metrowerks C⁄C++ Lite / Headers / Universal Headers 2.0.1f / SCSI.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-03-22  |  42.2 KB  |  1,054 lines  |  [TEXT/MMCC]

  1. /*
  2.      File:        SCSI.h
  3.  
  4.      Contains:    SCSI Manager Interfaces.
  5.  
  6.      Version:    Technology:    System 7.5
  7.                  Package:    Universal Interfaces 2.0 in “MPW Latest” on ETO #17
  8.  
  9.      Copyright:    © 1984-1995 by Apple Computer, Inc.
  10.                  All rights reserved.
  11.  
  12.      Bugs?:        If you find a problem with this file, use the Apple Bug Reporter
  13.                  stack.  Include the file and version information (from above)
  14.                  in the problem description and send to:
  15.                      Internet:    apple.bugs@applelink.apple.com
  16.                      AppleLink:    APPLE.BUGS
  17.  
  18. */
  19.  
  20. #ifndef __SCSI__
  21. #define __SCSI__
  22.  
  23.  
  24. #ifndef __TYPES__
  25. #include <Types.h>
  26. #endif
  27. /*    #include <ConditionalMacros.h>                                */
  28.  
  29. #ifndef __MIXEDMODE__
  30. #include <MixedMode.h>
  31. #endif
  32.  
  33. #ifdef __cplusplus
  34. extern "C" {
  35. #endif
  36.  
  37. #if PRAGMA_ALIGN_SUPPORTED
  38. #pragma options align=mac68k
  39. #endif
  40.  
  41. #if PRAGMA_IMPORT_SUPPORTED
  42. #pragma import on
  43. #endif
  44.  
  45.  
  46. enum {
  47.     scInc                        = 1,
  48.     scNoInc                        = 2,
  49.     scAdd                        = 3,
  50.     scMove                        = 4,
  51.     scLoop                        = 5,
  52.     scNop                        = 6,
  53.     scStop                        = 7,
  54.     scComp                        = 8
  55. };
  56.  
  57. /* SCSI Manager errors */
  58. enum {
  59.     scCommErr                    = 2,                            /* communications error, operation timeout */
  60.     scArbNBErr                    = 3,                            /* arbitration timeout waiting for not BSY */
  61.     scBadParmsErr                = 4,                            /* bad parameter or TIB opcode */
  62.     scPhaseErr                    = 5,                            /* SCSI bus not in correct phase for attempted operation */
  63.     scCompareErr                = 6,                            /* data compare error */
  64.     scMgrBusyErr                = 7,                            /* SCSI Manager busy  */
  65.     scSequenceErr                = 8,                            /* attempted operation is out of sequence */
  66.     scBusTOErr                    = 9,                            /* CPU bus timeout */
  67.     scComplPhaseErr                = 10                            /* SCSI bus wasn't in Status phase */
  68. };
  69.  
  70. /* Signatures */
  71. enum {
  72.     sbSIGWord                    = 0x4552,                        /* signature word for Block 0 ('ER') */
  73.     sbMac                        = 1,                            /* system type for Mac */
  74.     pMapSIG                        = 0x504D,                        /* partition map signature ('PM') */
  75.     pdSigWord                    = 0x5453
  76. };
  77.  
  78. enum {
  79.     oldPMSigWord                = pdSigWord,
  80.     newPMSigWord                = pMapSIG
  81. };
  82.  
  83. /* Driver Descriptor Map */
  84. struct Block0 {
  85.     unsigned short                    sbSig;                        /* unique value for SCSI block 0 */
  86.     unsigned short                    sbBlkSize;                    /* block size of device */
  87.     unsigned long                    sbBlkCount;                    /* number of blocks on device */
  88.     unsigned short                    sbDevType;                    /* device type */
  89.     unsigned short                    sbDevId;                    /* device id */
  90.     unsigned long                    sbData;                        /* not used */
  91.     unsigned short                    sbDrvrCount;                /* driver descriptor count */
  92.     unsigned long                    ddBlock;                    /* 1st driver's starting block */
  93.     unsigned short                    ddSize;                        /* size of 1st driver (512-byte blks) */
  94.     unsigned short                    ddType;                        /* system type (1 for Mac+) */
  95.     unsigned short                    ddPad[243];                    /* ARRAY[0..242] OF INTEGER; not used */
  96. };
  97. typedef struct Block0 Block0;
  98.  
  99. /* Partition Map Entry */
  100. struct Partition {
  101.     unsigned short                    pmSig;                        /* unique value for map entry blk */
  102.     unsigned short                    pmSigPad;                    /* currently unused */
  103.     unsigned long                    pmMapBlkCnt;                /* # of blks in partition map */
  104.     unsigned long                    pmPyPartStart;                /* physical start blk of partition */
  105.     unsigned long                    pmPartBlkCnt;                /* # of blks in this partition */
  106.     unsigned char                    pmPartName[32];                /* ASCII partition name */
  107.     unsigned char                    pmParType[32];                /* ASCII partition type */
  108.     unsigned long                    pmLgDataStart;                /* log. # of partition's 1st data blk */
  109.     unsigned long                    pmDataCnt;                    /* # of blks in partition's data area */
  110.     unsigned long                    pmPartStatus;                /* bit field for partition status */
  111.     unsigned long                    pmLgBootStart;                /* log. blk of partition's boot code */
  112.     unsigned long                    pmBootSize;                    /* number of bytes in boot code */
  113.     unsigned long                    pmBootAddr;                    /* memory load address of boot code */
  114.     unsigned long                    pmBootAddr2;                /* currently unused */
  115.     unsigned long                    pmBootEntry;                /* entry point of boot code */
  116.     unsigned long                    pmBootEntry2;                /* currently unused */
  117.     unsigned long                    pmBootCksum;                /* checksum of boot code */
  118.     unsigned char                    pmProcessor[16];            /* ASCII for the processor type */
  119.     unsigned short                    pmPad[188];                    /* 512 bytes long currently unused */
  120. };
  121. typedef struct Partition Partition;
  122.  
  123. /* TIB instruction */
  124. struct SCSIInstr {
  125.     unsigned short                    scOpcode;
  126.     long                            scParam1;
  127.     long                            scParam2;
  128. };
  129. typedef struct SCSIInstr SCSIInstr;
  130.  
  131. extern pascal OSErr SCSIReset(void)
  132.  TWOWORDINLINE(0x4267, 0xA815);
  133. extern pascal OSErr SCSIGet(void)
  134.  THREEWORDINLINE(0x3F3C, 0x0001, 0xA815);
  135. extern pascal OSErr SCSISelect(short targetID)
  136.  THREEWORDINLINE(0x3F3C, 0x0002, 0xA815);
  137. extern pascal OSErr SCSICmd(Ptr buffer, short count)
  138.  THREEWORDINLINE(0x3F3C, 0x0003, 0xA815);
  139. extern pascal OSErr SCSIRead(Ptr tibPtr)
  140.  THREEWORDINLINE(0x3F3C, 0x0005, 0xA815);
  141. extern pascal OSErr SCSIRBlind(Ptr tibPtr)
  142.  THREEWORDINLINE(0x3F3C, 0x0008, 0xA815);
  143. extern pascal OSErr SCSIWrite(Ptr tibPtr)
  144.  THREEWORDINLINE(0x3F3C, 0x0006, 0xA815);
  145. extern pascal OSErr SCSIWBlind(Ptr tibPtr)
  146.  THREEWORDINLINE(0x3F3C, 0x0009, 0xA815);
  147. extern pascal OSErr SCSIComplete(short *stat, short *message, unsigned long wait)
  148.  THREEWORDINLINE(0x3F3C, 0x0004, 0xA815);
  149. extern pascal short SCSIStat(void)
  150.  THREEWORDINLINE(0x3F3C, 0x000A, 0xA815);
  151. extern pascal OSErr SCSISelAtn(short targetID)
  152.  THREEWORDINLINE(0x3F3C, 0x000B, 0xA815);
  153. extern pascal OSErr SCSIMsgIn(short *message)
  154.  THREEWORDINLINE(0x3F3C, 0x000C, 0xA815);
  155. extern pascal OSErr SCSIMsgOut(short message)
  156.  THREEWORDINLINE(0x3F3C, 0x000D, 0xA815);
  157. /*——————————————————————— New SCSI Manager Interface ———————————————————————*/
  158.  
  159. enum {
  160.     scsiVERSION                    = 43
  161. };
  162.  
  163. /* SCSI Manager function codes */
  164. enum {
  165.     SCSINop                        = 0x00,                            /* Execute nothing                                         */
  166.     SCSIExecIO                    = 0x01,                            /* Execute the specified IO                             */
  167.     SCSIBusInquiry                = 0x03,                            /* Get parameters for entire path of HBAs                 */
  168.     SCSIReleaseQ                = 0x04,                            /* Release the frozen SIM queue for particular LUN         */
  169.     SCSIAbortCommand            = 0x10,                            /* Abort the selected Control Block                      */
  170.     SCSIResetBus                = 0x11,                            /* Reset the SCSI bus                                      */
  171.     SCSIResetDevice                = 0x12,                            /* Reset the SCSI device                                  */
  172.     SCSITerminateIO                = 0x13,                            /* Terminate any pending IO                              */
  173.     SCSIGetVirtualIDInfo        = 0x80,                            /* Find out which bus old ID is on                         */
  174.     SCSILoadDriver                = 0x82,                            /* Load a driver for a device ident                     */
  175.     SCSIOldCall                    = 0x84,                            /* XPT->SIM private call for old-API                     */
  176.     SCSICreateRefNumXref        = 0x85,                            /* Register a DeviceIdent to drvr RefNum xref             */
  177.     SCSILookupRefNumXref        = 0x86,                            /* Get DeviceIdent to drvr RefNum xref                     */
  178.     SCSIRemoveRefNumXref        = 0x87,                            /* Remove a DeviceIdent to drvr RefNum xref             */
  179.     SCSIRegisterWithNewXPT        = 0x88,                            /* XPT has changed - SIM needs to re-register itself     */
  180.     vendorUnique                = 0xC0                            /* 0xC0 thru 0xFF */
  181. };
  182.  
  183. /* SCSI Callback Procedure Prototypes */
  184. /* SCSIInterruptPollProcPtr is obsolete (use SCSIInterruptProcPtr) but still here for compatibility */
  185. typedef pascal void (*SCSICallbackProcPtr)(void *scsiPB);
  186. typedef void (*AENCallbackProcPtr)(void);
  187. typedef OSErr (*SIMInitProcPtr)(Ptr SIMinfoPtr);
  188. typedef void (*SIMActionProcPtr)(void *scsiPB, Ptr SIMGlobals);
  189. typedef void (*SCSIProcPtr)(void);
  190. typedef void (*SCSIMakeCallbackProcPtr)(void *scsiPB);
  191. typedef long (*SCSIInterruptPollProcPtr)(Ptr SIMGlobals);
  192. typedef long (*SCSIInterruptProcPtr)(Ptr SIMGlobals);
  193.  
  194. #if GENERATINGCFM
  195. typedef UniversalProcPtr SCSICallbackUPP;
  196. typedef UniversalProcPtr AENCallbackUPP;
  197. typedef UniversalProcPtr SIMInitUPP;
  198. typedef UniversalProcPtr SIMActionUPP;
  199. typedef UniversalProcPtr SCSIUPP;
  200. typedef UniversalProcPtr SCSIMakeCallbackUPP;
  201. typedef UniversalProcPtr SCSIInterruptPollUPP;
  202. typedef UniversalProcPtr SCSIInterruptUPP;
  203. #else
  204. typedef SCSICallbackProcPtr SCSICallbackUPP;
  205. typedef AENCallbackProcPtr AENCallbackUPP;
  206. typedef SIMInitProcPtr SIMInitUPP;
  207. typedef SIMActionProcPtr SIMActionUPP;
  208. typedef SCSIProcPtr SCSIUPP;
  209. typedef SCSIMakeCallbackProcPtr SCSIMakeCallbackUPP;
  210. typedef SCSIInterruptPollProcPtr SCSIInterruptPollUPP;
  211. typedef SCSIInterruptProcPtr SCSIInterruptUPP;
  212. #endif
  213.  
  214. enum {
  215.     uppSCSICallbackProcInfo = kPascalStackBased
  216.          | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(void*))),
  217.     uppAENCallbackProcInfo = kCStackBased,
  218.     uppSIMInitProcInfo = kCStackBased
  219.          | RESULT_SIZE(SIZE_CODE(sizeof(OSErr)))
  220.          | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(Ptr))),
  221.     uppSIMActionProcInfo = kCStackBased
  222.          | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(void*)))
  223.          | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(Ptr))),
  224.     uppSCSIProcInfo = kCStackBased,
  225.     uppSCSIMakeCallbackProcInfo = kCStackBased
  226.          | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(void*))),
  227.     uppSCSIInterruptPollProcInfo = kCStackBased
  228.          | RESULT_SIZE(SIZE_CODE(sizeof(long)))
  229.          | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(Ptr))),
  230.     uppSCSIInterruptProcInfo = kCStackBased
  231.          | RESULT_SIZE(SIZE_CODE(sizeof(long)))
  232.          | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(Ptr)))
  233. };
  234.  
  235. #if GENERATINGCFM
  236. #define NewSCSICallbackProc(userRoutine)        \
  237.         (SCSICallbackUPP) NewRoutineDescriptor((ProcPtr)(userRoutine), uppSCSICallbackProcInfo, GetCurrentArchitecture())
  238. #define NewAENCallbackProc(userRoutine)        \
  239.         (AENCallbackUPP) NewRoutineDescriptor((ProcPtr)(userRoutine), uppAENCallbackProcInfo, GetCurrentArchitecture())
  240. #define NewSIMInitProc(userRoutine)        \
  241.         (SIMInitUPP) NewRoutineDescriptor((ProcPtr)(userRoutine), uppSIMInitProcInfo, GetCurrentArchitecture())
  242. #define NewSIMActionProc(userRoutine)        \
  243.         (SIMActionUPP) NewRoutineDescriptor((ProcPtr)(userRoutine), uppSIMActionProcInfo, GetCurrentArchitecture())
  244. #define NewSCSIProc(userRoutine)        \
  245.         (SCSIUPP) NewRoutineDescriptor((ProcPtr)(userRoutine), uppSCSIProcInfo, GetCurrentArchitecture())
  246. #define NewSCSIMakeCallbackProc(userRoutine)        \
  247.         (SCSIMakeCallbackUPP) NewRoutineDescriptor((ProcPtr)(userRoutine), uppSCSIMakeCallbackProcInfo, GetCurrentArchitecture())
  248. #define NewSCSIInterruptPollProc(userRoutine)        \
  249.         (SCSIInterruptPollUPP) NewRoutineDescriptor((ProcPtr)(userRoutine), uppSCSIInterruptPollProcInfo, GetCurrentArchitecture())
  250. #define NewSCSIInterruptProc(userRoutine)        \
  251.         (SCSIInterruptUPP) NewRoutineDescriptor((ProcPtr)(userRoutine), uppSCSIInterruptProcInfo, GetCurrentArchitecture())
  252. #else
  253. #define NewSCSICallbackProc(userRoutine)        \
  254.         ((SCSICallbackUPP) (userRoutine))
  255. #define NewAENCallbackProc(userRoutine)        \
  256.         ((AENCallbackUPP) (userRoutine))
  257. #define NewSIMInitProc(userRoutine)        \
  258.         ((SIMInitUPP) (userRoutine))
  259. #define NewSIMActionProc(userRoutine)        \
  260.         ((SIMActionUPP) (userRoutine))
  261. #define NewSCSIProc(userRoutine)        \
  262.         ((SCSIUPP) (userRoutine))
  263. #define NewSCSIMakeCallbackProc(userRoutine)        \
  264.         ((SCSIMakeCallbackUPP) (userRoutine))
  265. #define NewSCSIInterruptPollProc(userRoutine)        \
  266.         ((SCSIInterruptPollUPP) (userRoutine))
  267. #define NewSCSIInterruptProc(userRoutine)        \
  268.         ((SCSIInterruptUPP) (userRoutine))
  269. #endif
  270.  
  271. #if GENERATINGCFM
  272. #define CallSCSICallbackProc(userRoutine, scsiPB)        \
  273.         CallUniversalProc((UniversalProcPtr)(userRoutine), uppSCSICallbackProcInfo, (scsiPB))
  274. #define CallAENCallbackProc(userRoutine)        \
  275.         CallUniversalProc((UniversalProcPtr)(userRoutine), uppAENCallbackProcInfo)
  276. #define CallSIMInitProc(userRoutine, SIMinfoPtr)        \
  277.         CallUniversalProc((UniversalProcPtr)(userRoutine), uppSIMInitProcInfo, (SIMinfoPtr))
  278. #define CallSIMActionProc(userRoutine, scsiPB, SIMGlobals)        \
  279.         CallUniversalProc((UniversalProcPtr)(userRoutine), uppSIMActionProcInfo, (scsiPB), (SIMGlobals))
  280. #define CallSCSIProc(userRoutine)        \
  281.         CallUniversalProc((UniversalProcPtr)(userRoutine), uppSCSIProcInfo)
  282. #define CallSCSIMakeCallbackProc(userRoutine, scsiPB)        \
  283.         CallUniversalProc((UniversalProcPtr)(userRoutine), uppSCSIMakeCallbackProcInfo, (scsiPB))
  284. #define CallSCSIInterruptPollProc(userRoutine, SIMGlobals)        \
  285.         CallUniversalProc((UniversalProcPtr)(userRoutine), uppSCSIInterruptPollProcInfo, (SIMGlobals))
  286. #define CallSCSIInterruptProc(userRoutine, SIMGlobals)        \
  287.         CallUniversalProc((UniversalProcPtr)(userRoutine), uppSCSIInterruptProcInfo, (SIMGlobals))
  288. #else
  289. #define CallSCSICallbackProc(userRoutine, scsiPB)        \
  290.         (*(userRoutine))((scsiPB))
  291. #define CallAENCallbackProc(userRoutine)        \
  292.         (*(userRoutine))()
  293. #define CallSIMInitProc(userRoutine, SIMinfoPtr)        \
  294.         (*(userRoutine))((SIMinfoPtr))
  295. #define CallSIMActionProc(userRoutine, scsiPB, SIMGlobals)        \
  296.         (*(userRoutine))((scsiPB), (SIMGlobals))
  297. #define CallSCSIProc(userRoutine)        \
  298.         (*(userRoutine))()
  299. #define CallSCSIMakeCallbackProc(userRoutine, scsiPB)        \
  300.         (*(userRoutine))((scsiPB))
  301. #define CallSCSIInterruptPollProc(userRoutine, SIMGlobals)        \
  302.         (*(userRoutine))((SIMGlobals))
  303. #define CallSCSIInterruptProc(userRoutine, SIMGlobals)        \
  304.         (*(userRoutine))((SIMGlobals))
  305. #endif
  306.  
  307. enum {
  308.     handshakeDataLength            = 8,                            /* Handshake data length */
  309.     maxCDBLength                = 16,                            /* Space for the CDB bytes/pointer */
  310.     vendorIDLength                = 16                            /* ASCII string len for Vendor ID  */
  311. };
  312.  
  313. /* Define DeviceIdent structure */
  314. struct DeviceIdent {
  315.     UInt8                            diReserved;                    /* reserved                 */
  316.     UInt8                            bus;                        /* SCSI - Bus Number        */
  317.     UInt8                            targetID;                    /* SCSI - Target SCSI ID    */
  318.     UInt8                            LUN;                        /* SCSI - LUN                  */
  319. };
  320. typedef struct DeviceIdent DeviceIdent;
  321.  
  322. /* Command Descriptor Block structure */
  323. union CDB {
  324.     UInt8                            *cdbPtr;                    /* pointer to the CDB, or */
  325.     UInt8                            cdbBytes[maxCDBLength];        /* the actual CDB to send */
  326. };
  327. typedef union CDB CDB, *CDBPtr;
  328.  
  329. struct SGRecord {
  330.     Ptr                                SGAddr;
  331.     UInt32                            SGCount;
  332. };
  333. typedef struct SGRecord SGRecord;
  334.  
  335. /* SCSI Phases (used by SIMs to support the Original SCSI Manager */
  336.  
  337. enum {
  338.     kDataOutPhase,                                                /* Encoded MSG, C/D, I/O bits */
  339.     kDataInPhase,
  340.     kCommandPhase,
  341.     kStatusPhase,
  342.     kPhaseIllegal0,
  343.     kPhaseIllegal1,
  344.     kMessageOutPhase,
  345.     kMessageInPhase,
  346.     kBusFreePhase,                                                /* Additional Phases */
  347.     kArbitratePhase,
  348.     kSelectPhase,
  349.     kMessageInPhaseNACK                                            /* Message In Phase with ACK hanging on the bus */
  350. };
  351.  
  352. #define SCSIPBHdr                 \
  353.     struct SCSIHdr * qLink;        \
  354.     short    scsiReserved1;            \
  355.     UInt16    scsiPBLength;            \
  356.     UInt8    scsiFunctionCode;        \
  357.     UInt8    scsiReserved2;            \
  358.     OSErr    scsiResult;                \
  359.     DeviceIdent    scsiDevice;        \
  360.     SCSICallbackUPP    scsiCompletion;     \
  361.     UInt32    scsiFlags;                \
  362.     UInt8 *    scsiDriverStorage;        \
  363.     Ptr    scsiXPTprivate;            \
  364.     long    scsiReserved3;
  365. struct SCSIHdr {
  366.     struct SCSIHdr                    *qLink;
  367.     short                            scsiReserved1;
  368.     UInt16                            scsiPBLength;
  369.     UInt8                            scsiFunctionCode;
  370.     UInt8                            scsiReserved2;
  371.     OSErr                            scsiResult;
  372.     DeviceIdent                        scsiDevice;
  373.     SCSICallbackUPP                    scsiCompletion;
  374.     UInt32                            scsiFlags;
  375.     UInt8                            *scsiDriverStorage;
  376.     Ptr                                scsiXPTprivate;
  377.     long                            scsiReserved3;
  378. };
  379. typedef struct SCSIHdr SCSIHdr;
  380.  
  381. struct SCSI_PB {
  382.     struct SCSIHdr                    *qLink;
  383.     short                            scsiReserved1;
  384.     UInt16                            scsiPBLength;
  385.     UInt8                            scsiFunctionCode;
  386.     UInt8                            scsiReserved2;
  387.     OSErr                            scsiResult;
  388.     DeviceIdent                        scsiDevice;
  389.     SCSICallbackUPP                    scsiCompletion;
  390.     UInt32                            scsiFlags;
  391.     UInt8                            *scsiDriverStorage;
  392.     Ptr                                scsiXPTprivate;
  393.     long                            scsiReserved3;
  394. };
  395. typedef struct SCSI_PB SCSI_PB;
  396.  
  397. #define SCSI_IO_Macro             \
  398.     SCSIPBHdr                        \
  399.     UInt16    scsiResultFlags;        \
  400.     UInt16    scsiReserved3pt5;        \
  401.     UInt8 *    scsiDataPtr;            \
  402.     UInt32    scsiDataLength;            \
  403.     UInt8 *    scsiSensePtr;            \
  404.     UInt8    scsiSenseLength;            \
  405.     UInt8    scsiCDBLength;            \
  406.     UInt16    scsiSGListCount;        \
  407.     UInt32    scsiReserved4;            \
  408.     UInt8    scsiSCSIstatus;            \
  409.     SInt8    scsiSenseResidual;        \
  410.     UInt16    scsiReserved5;            \
  411.     long    scsiDataResidual;            \
  412.     CDB    scsiCDB;                    \
  413.     long    scsiTimeout;                \
  414.     UInt8 *    scsiReserved5pt5;        \
  415.     UInt16    scsiReserved5pt6;        \
  416.     UInt16    scsiIOFlags;            \
  417.     UInt8    scsiTagAction;            \
  418.     UInt8    scsiReserved6;            \
  419.     UInt16    scsiReserved7;            \
  420.     UInt16    scsiSelectTimeout;        \
  421.     UInt8    scsiDataType;            \
  422.     UInt8    scsiTransferType;        \
  423.     UInt32    scsiReserved8;            \
  424.     UInt32    scsiReserved9;            \
  425.     UInt16    scsiHandshake[handshakeDataLength];     \
  426.     UInt32    scsiReserved10;            \
  427.     UInt32    scsiReserved11;            \
  428.     struct SCSI_IO *scsiCommandLink;     \
  429.                                 \
  430.     UInt8    scsiSIMpublics[8];        \
  431.     UInt8    scsiAppleReserved6[8];     \
  432.                                 \
  433.                                 \
  434.                                 \
  435.     UInt16    scsiCurrentPhase;        \
  436.     short    scsiSelector;            \
  437.     OSErr    scsiOldCallResult;        \
  438.     UInt8    scsiSCSImessage;            \
  439.     UInt8    XPTprivateFlags;            \
  440.     UInt8    XPTextras[12];
  441. struct SCSI_IO {
  442.     struct SCSIHdr                    *qLink;
  443.     short                            scsiReserved1;
  444.     UInt16                            scsiPBLength;
  445.     UInt8                            scsiFunctionCode;
  446.     UInt8                            scsiReserved2;
  447.     OSErr                            scsiResult;
  448.     DeviceIdent                        scsiDevice;
  449.     SCSICallbackUPP                    scsiCompletion;
  450.     UInt32                            scsiFlags;
  451.     UInt8                            *scsiDriverStorage;
  452.     Ptr                                scsiXPTprivate;
  453.     long                            scsiReserved3;
  454.     UInt16                            scsiResultFlags;
  455.     UInt16                            scsiReserved3pt5;
  456.     UInt8                            *scsiDataPtr;
  457.     UInt32                            scsiDataLength;
  458.     UInt8                            *scsiSensePtr;
  459.     UInt8                            scsiSenseLength;
  460.     UInt8                            scsiCDBLength;
  461.     UInt16                            scsiSGListCount;
  462.     UInt32                            scsiReserved4;
  463.     UInt8                            scsiSCSIstatus;
  464.     SInt8                            scsiSenseResidual;
  465.     UInt16                            scsiReserved5;
  466.     long                            scsiDataResidual;
  467.     CDB                                scsiCDB;
  468.     long                            scsiTimeout;
  469.     UInt8                            *scsiReserved5pt5;
  470.     UInt16                            scsiReserved5pt6;
  471.     UInt16                            scsiIOFlags;
  472.     UInt8                            scsiTagAction;
  473.     UInt8                            scsiReserved6;
  474.     UInt16                            scsiReserved7;
  475.     UInt16                            scsiSelectTimeout;
  476.     UInt8                            scsiDataType;
  477.     UInt8                            scsiTransferType;
  478.     UInt32                            scsiReserved8;
  479.     UInt32                            scsiReserved9;
  480.     UInt16                            scsiHandshake[handshakeDataLength];
  481.     UInt32                            scsiReserved10;
  482.     UInt32                            scsiReserved11;
  483.     struct SCSI_IO                    *scsiCommandLink;
  484.     UInt8                            scsiSIMpublics[8];
  485.     UInt8                            scsiAppleReserved6[8];
  486.     UInt16                            scsiCurrentPhase;
  487.     short                            scsiSelector;
  488.     OSErr                            scsiOldCallResult;
  489.     UInt8                            scsiSCSImessage;
  490.     UInt8                            XPTprivateFlags;
  491.     UInt8                            XPTextras[12];
  492. };
  493. typedef struct SCSI_IO SCSI_IO;
  494.  
  495. typedef SCSI_IO SCSIExecIOPB;
  496.  
  497. /* Bus inquiry PB */
  498. struct SCSIBusInquiryPB {
  499.     struct SCSIHdr                    *qLink;
  500.     short                            scsiReserved1;
  501.     UInt16                            scsiPBLength;
  502.     UInt8                            scsiFunctionCode;
  503.     UInt8                            scsiReserved2;
  504.     OSErr                            scsiResult;
  505.     DeviceIdent                        scsiDevice;
  506.     SCSICallbackUPP                    scsiCompletion;
  507.     UInt32                            scsiFlags;
  508.     UInt8                            *scsiDriverStorage;
  509.     Ptr                                scsiXPTprivate;
  510.     long                            scsiReserved3;
  511.     UInt16                            scsiEngineCount;            /* <- Number of engines on HBA                         */
  512.     UInt16                            scsiMaxTransferType;        /* <- Number of transfer types for this HBA            */
  513.     UInt32                            scsiDataTypes;                /* <- which data types are supported by this SIM     */
  514.     UInt16                            scsiIOpbSize;                /* <- Size of SCSI_IO PB for this SIM/HBA             */
  515.     UInt16                            scsiMaxIOpbSize;            /* <- Size of max SCSI_IO PB for all SIM/HBAs         */
  516.     UInt32                            scsiFeatureFlags;            /* <- Supported features flags field                 */
  517.     UInt8                            scsiVersionNumber;            /* <- Version number for the SIM/HBA                 */
  518.     UInt8                            scsiHBAInquiry;                /* <- Mimic of INQ byte 7 for the HBA                 */
  519.     UInt8                            scsiTargetModeFlags;        /* <- Flags for target mode support                 */
  520.     UInt8                            scsiScanFlags;                /* <- Scan related feature flags                     */
  521.     UInt32                            scsiSIMPrivatesPtr;            /* <- Ptr to SIM private data area                     */
  522.     UInt32                            scsiSIMPrivatesSize;        /* <- Size of SIM private data area                 */
  523.     UInt32                            scsiAsyncFlags;                /* <- Event cap. for Async Callback                 */
  524.     UInt8                            scsiHiBusID;                /* <- Highest path ID in the subsystem              */
  525.     UInt8                            scsiInitiatorID;            /* <- ID of the HBA on the SCSI bus                 */
  526.     UInt16                            scsiBIReserved0;            /*                                                    */
  527.     UInt32                            scsiBIReserved1;            /* <-                                                  */
  528.     UInt32                            scsiFlagsSupported;            /* <- which scsiFlags are supported                 */
  529.     UInt16                            scsiIOFlagsSupported;        /* <- which scsiIOFlags are supported                 */
  530.     UInt16                            scsiWeirdStuff;                /* <-                                                 */
  531.     UInt16                            scsiMaxTarget;                /* <- maximum Target number supported                 */
  532.     UInt16                            scsiMaxLUN;                    /* <- maximum Logical Unit number supported         */
  533.     char                            scsiSIMVendor[vendorIDLength]; /* <- Vendor ID of SIM (or XPT if bus<FF)         */
  534.     char                            scsiHBAVendor[vendorIDLength]; /* <- Vendor ID of the HBA                         */
  535.     char                            scsiControllerFamily[vendorIDLength]; /* <- Family of SCSI Controller                 */
  536.     char                            scsiControllerType[vendorIDLength]; /* <- Specific Model of SCSI Controller used     */
  537.     char                            scsiXPTversion[4];            /* <- version number of XPT                         */
  538.     char                            scsiSIMversion[4];            /* <- version number of SIM                         */
  539.     char                            scsiHBAversion[4];            /* <- version number of HBA                         */
  540.     UInt8                            scsiHBAslotType;            /* <- type of "slot" that this HBA is in            */
  541.     UInt8                            scsiHBAslotNumber;            /* <- slot number of this HBA                         */
  542.     UInt16                            scsiSIMsRsrcID;                /* <- resource ID of this SIM                         */
  543.     UInt16                            scsiBIReserved3;            /* <-                                                 */
  544.     UInt16                            scsiAdditionalLength;        /* <- additional BusInquiry PB len                    */
  545. };
  546. typedef struct SCSIBusInquiryPB SCSIBusInquiryPB;
  547.  
  548. /* Abort SIM Request PB */
  549. struct SCSIAbortCommandPB {
  550.     struct SCSIHdr                    *qLink;
  551.     short                            scsiReserved1;
  552.     UInt16                            scsiPBLength;
  553.     UInt8                            scsiFunctionCode;
  554.     UInt8                            scsiReserved2;
  555.     OSErr                            scsiResult;
  556.     DeviceIdent                        scsiDevice;
  557.     SCSICallbackUPP                    scsiCompletion;
  558.     UInt32                            scsiFlags;
  559.     UInt8                            *scsiDriverStorage;
  560.     Ptr                                scsiXPTprivate;
  561.     long                            scsiReserved3;
  562.     SCSI_IO                            *scsiIOptr;                    /* Pointer to the PB to abort                        */
  563. };
  564. typedef struct SCSIAbortCommandPB SCSIAbortCommandPB;
  565.  
  566. /* Terminate I/O Process Request PB */
  567. struct SCSITerminateIOPB {
  568.     struct SCSIHdr                    *qLink;
  569.     short                            scsiReserved1;
  570.     UInt16                            scsiPBLength;
  571.     UInt8                            scsiFunctionCode;
  572.     UInt8                            scsiReserved2;
  573.     OSErr                            scsiResult;
  574.     DeviceIdent                        scsiDevice;
  575.     SCSICallbackUPP                    scsiCompletion;
  576.     UInt32                            scsiFlags;
  577.     UInt8                            *scsiDriverStorage;
  578.     Ptr                                scsiXPTprivate;
  579.     long                            scsiReserved3;
  580.     SCSI_IO                            *scsiIOptr;                    /* Pointer to the PB to terminate                     */
  581. };
  582. typedef struct SCSITerminateIOPB SCSITerminateIOPB;
  583.  
  584. /* Reset SCSI Bus PB */
  585. struct SCSIResetBusPB {
  586.     struct SCSIHdr                    *qLink;
  587.     short                            scsiReserved1;
  588.     UInt16                            scsiPBLength;
  589.     UInt8                            scsiFunctionCode;
  590.     UInt8                            scsiReserved2;
  591.     OSErr                            scsiResult;
  592.     DeviceIdent                        scsiDevice;
  593.     SCSICallbackUPP                    scsiCompletion;
  594.     UInt32                            scsiFlags;
  595.     UInt8                            *scsiDriverStorage;
  596.     Ptr                                scsiXPTprivate;
  597.     long                            scsiReserved3;
  598. };
  599. typedef struct SCSIResetBusPB SCSIResetBusPB;
  600.  
  601. /* Reset SCSI Device PB */
  602. struct SCSIResetDevicePB {
  603.     struct SCSIHdr                    *qLink;
  604.     short                            scsiReserved1;
  605.     UInt16                            scsiPBLength;
  606.     UInt8                            scsiFunctionCode;
  607.     UInt8                            scsiReserved2;
  608.     OSErr                            scsiResult;
  609.     DeviceIdent                        scsiDevice;
  610.     SCSICallbackUPP                    scsiCompletion;
  611.     UInt32                            scsiFlags;
  612.     UInt8                            *scsiDriverStorage;
  613.     Ptr                                scsiXPTprivate;
  614.     long                            scsiReserved3;
  615. };
  616. typedef struct SCSIResetDevicePB SCSIResetDevicePB;
  617.  
  618. /* Release SIM Queue PB */
  619. struct SCSIReleaseQPB {
  620.     struct SCSIHdr                    *qLink;
  621.     short                            scsiReserved1;
  622.     UInt16                            scsiPBLength;
  623.     UInt8                            scsiFunctionCode;
  624.     UInt8                            scsiReserved2;
  625.     OSErr                            scsiResult;
  626.     DeviceIdent                        scsiDevice;
  627.     SCSICallbackUPP                    scsiCompletion;
  628.     UInt32                            scsiFlags;
  629.     UInt8                            *scsiDriverStorage;
  630.     Ptr                                scsiXPTprivate;
  631.     long                            scsiReserved3;
  632. };
  633. typedef struct SCSIReleaseQPB SCSIReleaseQPB;
  634.  
  635. /* SCSI Get Virtual ID Info PB */
  636. struct SCSIGetVirtualIDInfoPB {
  637.     struct SCSIHdr                    *qLink;
  638.     short                            scsiReserved1;
  639.     UInt16                            scsiPBLength;
  640.     UInt8                            scsiFunctionCode;
  641.     UInt8                            scsiReserved2;
  642.     OSErr                            scsiResult;
  643.     DeviceIdent                        scsiDevice;
  644.     SCSICallbackUPP                    scsiCompletion;
  645.     UInt32                            scsiFlags;
  646.     UInt8                            *scsiDriverStorage;
  647.     Ptr                                scsiXPTprivate;
  648.     long                            scsiReserved3;
  649.     UInt16                            scsiOldCallID;                /* -> SCSI ID of device in question             */
  650.     Boolean                            scsiExists;                    /* <- true if device exists                     */
  651.     SInt8                            filler;
  652. };
  653. typedef struct SCSIGetVirtualIDInfoPB SCSIGetVirtualIDInfoPB;
  654.  
  655. /* Create/Lookup/Remove RefNum for Device PB */
  656. struct SCSIDriverPB {
  657.     struct SCSIHdr                    *qLink;
  658.     short                            scsiReserved1;
  659.     UInt16                            scsiPBLength;
  660.     UInt8                            scsiFunctionCode;
  661.     UInt8                            scsiReserved2;
  662.     OSErr                            scsiResult;
  663.     DeviceIdent                        scsiDevice;
  664.     SCSICallbackUPP                    scsiCompletion;
  665.     UInt32                            scsiFlags;
  666.     UInt8                            *scsiDriverStorage;
  667.     Ptr                                scsiXPTprivate;
  668.     long                            scsiReserved3;
  669.     short                            scsiDriver;                    /* -> DriverRefNum, For SetDriver, <- For GetNextDriver */
  670.     UInt16                            scsiDriverFlags;            /* <> Details of driver/device                     */
  671.     DeviceIdent                        scsiNextDevice;                /* <- DeviceIdent of the NEXT Item in the list  */
  672. };
  673. typedef struct SCSIDriverPB SCSIDriverPB;
  674.  
  675. /* Load Driver PB */
  676. struct SCSILoadDriverPB {
  677.     struct SCSIHdr                    *qLink;
  678.     short                            scsiReserved1;
  679.     UInt16                            scsiPBLength;
  680.     UInt8                            scsiFunctionCode;
  681.     UInt8                            scsiReserved2;
  682.     OSErr                            scsiResult;
  683.     DeviceIdent                        scsiDevice;
  684.     SCSICallbackUPP                    scsiCompletion;
  685.     UInt32                            scsiFlags;
  686.     UInt8                            *scsiDriverStorage;
  687.     Ptr                                scsiXPTprivate;
  688.     long                            scsiReserved3;
  689.     short                            scsiLoadedRefNum;            /* <- SIM returns refnum of driver                     */
  690.     Boolean                            scsiDiskLoadFailed;            /* -> if true, indicates call after failure to load */
  691.     SInt8                            filler;
  692. };
  693. typedef struct SCSILoadDriverPB SCSILoadDriverPB;
  694.  
  695. /* Defines for the scsiTransferType field */
  696.  
  697. enum {
  698.     scsiTransferBlind            = 0,
  699.     scsiTransferPolled
  700. };
  701.  
  702. /* Defines for the scsiDataType field */
  703. enum {
  704.     scsiDataBuffer                = 0,                            /* single contiguous buffer supplied                  */
  705.     scsiDataTIB                    = 1,                            /* TIB supplied (ptr in scsiDataPtr)                 */
  706.     scsiDataSG                    = 2                                /* scatter/gather list supplied                      */
  707. };
  708.  
  709. /* Defines for the SCSIMgr scsiResult field in the PB header. */
  710. /*  $E100 thru  E1FF */
  711. /* -$1EFF thru -1E00 */
  712. /* -#7935 thru -7681  */
  713. /* = 0xE100 */
  714. enum {
  715.     scsiErrorBase                = -7936
  716. };
  717.  
  718. enum {
  719.     scsiRequestInProgress        = 1,                            /* 1     = PB request is in progress             */
  720. /* Execution failed  00-2F */
  721.     scsiRequestAborted            = scsiErrorBase + 2,            /* -7934 = PB request aborted by the host         */
  722.     scsiUnableToAbort            = scsiErrorBase + 3,            /* -7933 = Unable to Abort PB request             */
  723.     scsiNonZeroStatus            = scsiErrorBase + 4,            /* -7932 = PB request completed with an err     */
  724.     scsiUnused05                = scsiErrorBase + 5,            /* -7931 =                                      */
  725.     scsiUnused06                = scsiErrorBase + 6,            /* -7930 =                                      */
  726.     scsiUnused07                = scsiErrorBase + 7,            /* -7929 =                                      */
  727.     scsiUnused08                = scsiErrorBase + 8,            /* -7928 =                                      */
  728.     scsiUnableToTerminate        = scsiErrorBase + 9,            /* -7927 = Unable to Terminate I/O PB req         */
  729.     scsiSelectTimeout            = scsiErrorBase + 10,            /* -7926 = Target selection timeout             */
  730.     scsiCommandTimeout            = scsiErrorBase + 11,            /* -7925 = Command timeout                      */
  731.     scsiIdentifyMessageRejected    = scsiErrorBase + 12,            /* -7924 =                                      */
  732.     scsiMessageRejectReceived    = scsiErrorBase + 13,            /* -7923 = Message reject received                 */
  733.     scsiSCSIBusReset            = scsiErrorBase + 14,            /* -7922 = SCSI bus reset sent/received         */
  734.     scsiParityError                = scsiErrorBase + 15,            /* -7921 = Uncorrectable parity error occured     */
  735.     scsiAutosenseFailed            = scsiErrorBase + 16,            /* -7920 = Autosense: Request sense cmd fail     */
  736.     scsiUnused11                = scsiErrorBase + 17,            /* -7919 =                                      */
  737.     scsiDataRunError            = scsiErrorBase + 18,            /* -7918 = Data overrun/underrun error          */
  738.     scsiUnexpectedBusFree        = scsiErrorBase + 19,            /* -7917 = Unexpected BUS free                     */
  739.     scsiSequenceFailed            = scsiErrorBase + 20,            /* -7916 = Target bus phase sequence failure     */
  740.     scsiWrongDirection            = scsiErrorBase + 21,            /* -7915 = Data phase was in wrong direction     */
  741.     scsiUnused16                = scsiErrorBase + 22,            /* -7914 =                                      */
  742.     scsiBDRsent                    = scsiErrorBase + 23,            /* -7913 = A SCSI BDR msg was sent to target     */
  743.     scsiTerminated                = scsiErrorBase + 24,            /* -7912 = PB request terminated by the host     */
  744.     scsiNoNexus                    = scsiErrorBase + 25,            /* -7911 = Nexus is not established             */
  745.     scsiCDBReceived                = scsiErrorBase + 26,            /* -7910 = The SCSI CDB has been received         */
  746. /* Couldn't begin execution  30-3F */
  747.     scsiTooManyBuses            = scsiErrorBase + 48,            /* -7888 = Register failed because we're full    */
  748.     scsiBusy                    = scsiErrorBase + 49,            /* -7887 = SCSI subsystem is busy                 */
  749.     scsiProvideFail                = scsiErrorBase + 50,            /* -7886 = Unable to provide requ. capability    */
  750.     scsiDeviceNotThere            = scsiErrorBase + 51,            /* -7885 = SCSI device not installed/there      */
  751.     scsiNoHBA                    = scsiErrorBase + 52,            /* -7884 = No HBA detected Error                 */
  752.     scsiDeviceConflict            = scsiErrorBase + 53,            /* -7883 = sorry, max 1 refNum per DeviceIdent     */
  753.     scsiNoSuchXref                = scsiErrorBase + 54,            /* -7882 = no such RefNum xref                     */
  754.     scsiQLinkInvalid            = scsiErrorBase + 55,            /* -7881 = pre-linked PBs not supported            
  755.                                                                    (The QLink field was nonzero)        */
  756. /* Parameter errors  40-7F */
  757.     scsiPBLengthError            = scsiErrorBase + 64,            /* -7872 = (scsiPBLength is insuf'ct/invalid     */
  758.     scsiFunctionNotAvailable    = scsiErrorBase + 65,            /* -7871 = The requ. func is not available      */
  759.     scsiRequestInvalid            = scsiErrorBase + 66,            /* -7870 = PB request is invalid                 */
  760.     scsiBusInvalid                = scsiErrorBase + 67,            /* -7869 = Bus ID supplied is invalid              */
  761.     scsiTIDInvalid                = scsiErrorBase + 68,            /* -7868 = Target ID supplied is invalid         */
  762.     scsiLUNInvalid                = scsiErrorBase + 69,            /* -7867 = LUN supplied is invalid              */
  763.     scsiIDInvalid                = scsiErrorBase + 70,            /* -7866 = The initiator ID is invalid          */
  764.     scsiDataTypeInvalid            = scsiErrorBase + 71,            /* -7865 = scsiDataType requested not supported */
  765.     scsiTransferTypeInvalid        = scsiErrorBase + 72,            /* -7864 = scsiTransferType field is too high     */
  766.     scsiCDBLengthInvalid        = scsiErrorBase + 73            /* -7863 = scsiCDBLength field is too big         */
  767. };
  768.  
  769. enum {
  770.     scsiExecutionErrors            = scsiErrorBase,
  771.     scsiNotExecutedErrors        = scsiTooManyBuses,
  772.     scsiParameterErrors            = scsiPBLengthError
  773. };
  774.  
  775. /* Defines for the scsiResultFlags field */
  776. enum {
  777.     scsiSIMQFrozen                = 0x0001,                        /* The SIM queue is frozen w/this err            */
  778.     scsiAutosenseValid            = 0x0002,                        /* Autosense data valid for target              */
  779.     scsiBusNotFree                = 0x0004                        /* At time of callback, SCSI bus is not free    */
  780. };
  781.  
  782. /* Defines for the bit numbers of the scsiFlags field in the PB header for the SCSIExecIO function */
  783. enum {
  784.     kbSCSIDisableAutosense        = 29,                            /* Disable auto sense feature                     */
  785.     kbSCSIFlagReservedA            = 28,                            /*                                              */
  786.     kbSCSIFlagReserved0            = 27,                            /*                                              */
  787.     kbSCSICDBLinked                = 26,                            /* The PB contains a linked CDB                    */
  788.     kbSCSIQEnable                = 25,                            /* Target queue actions are enabled                */
  789.     kbSCSICDBIsPointer            = 24,                            /* The CDB field contains a pointer                */
  790.     kbSCSIFlagReserved1            = 23,                            /*                                                 */
  791.     kbSCSIInitiateSyncData        = 22,                            /* Attempt Sync data xfer and SDTR                */
  792.     kbSCSIDisableSyncData        = 21,                            /* Disable sync, go to async                    */
  793.     kbSCSISIMQHead                = 20,                            /* Place PB at the head of SIM Q                */
  794.     kbSCSISIMQFreeze            = 19,                            /* Return the SIM Q to frozen state                */
  795.     kbSCSISIMQNoFreeze            = 18,                            /* Disallow SIM Q freezing                        */
  796.     kbSCSIDoDisconnect            = 17,                            /* Definitely do disconnect                        */
  797.     kbSCSIDontDisconnect        = 16,                            /* Definitely don't disconnect                    */
  798.     kbSCSIDataReadyForDMA        = 15,                            /* Data buffer(s) are ready for DMA                */
  799.     kbSCSIFlagReserved3            = 14,                            /*                                                 */
  800.     kbSCSIDataPhysical            = 13,                            /* SG/Buffer data ptrs are physical                */
  801.     kbSCSISensePhysical            = 12,                            /* Autosense buffer ptr is physical                */
  802.     kbSCSIFlagReserved5            = 11,                            /*                                                 */
  803.     kbSCSIFlagReserved6            = 10,                            /*                                                 */
  804.     kbSCSIFlagReserved7            = 9,                            /*                                                 */
  805.     kbSCSIFlagReserved8            = 8,                            /*                                                 */
  806.     kbSCSIDataBufferValid        = 7,                            /* Data buffer valid                            */
  807.     kbSCSIStatusBufferValid        = 6,                            /* Status buffer valid                             */
  808.     kbSCSIMessageBufferValid    = 5,                            /* Message buffer valid                            */
  809.     kbSCSIFlagReserved9            = 4                                /*                                              */
  810. };
  811.  
  812. /* Defines for the bit masks of the scsiFlags field */
  813. enum {
  814.     scsiDirectionMask            = 0xC0000000,                    /* Data direction mask                        */
  815.     scsiDirectionNone            = 0xC0000000,                    /* Data direction (11: no data)                */
  816.     scsiDirectionReserved        = 0x00000000,                    /* Data direction (00: reserved)            */
  817.     scsiDirectionOut            = 0x80000000,                    /* Data direction (10: DATA OUT)            */
  818.     scsiDirectionIn                = 0x40000000,                    /* Data direction (01: DATA IN)                */
  819.     scsiDisableAutosense        = 0x20000000,                    /* Disable auto sense feature                */
  820.     scsiFlagReservedA            = 0x10000000,                    /*                                             */
  821.     scsiFlagReserved0            = 0x08000000,                    /*                                             */
  822.     scsiCDBLinked                = 0x04000000,                    /* The PB contains a linked CDB                */
  823.     scsiQEnable                    = 0x02000000,                    /* Target queue actions are enabled            */
  824.     scsiCDBIsPointer            = 0x01000000,                    /* The CDB field contains a pointer            */
  825.     scsiFlagReserved1            = 0x00800000,                    /*                                             */
  826.     scsiInitiateSyncData        = 0x00400000,                    /* Attempt Sync data xfer and SDTR            */
  827.     scsiDisableSyncData            = 0x00200000,                    /* Disable sync, go to async                */
  828.     scsiSIMQHead                = 0x00100000,                    /* Place PB at the head of SIM Q            */
  829.     scsiSIMQFreeze                = 0x00080000,                    /* Return the SIM Q to frozen state            */
  830.     scsiSIMQNoFreeze            = 0x00040000,                    /* Disallow SIM Q freezing                    */
  831.     scsiDoDisconnect            = 0x00020000,                    /* Definitely do disconnect                    */
  832.     scsiDontDisconnect            = 0x00010000,                    /* Definitely don't disconnect                */
  833.     scsiDataReadyForDMA            = 0x00008000,                    /* Data buffer(s) are ready for DMA            */
  834.     scsiFlagReserved3            = 0x00004000,                    /*  */
  835.     scsiDataPhysical            = 0x00002000,                    /* SG/Buffer data ptrs are physical            */
  836.     scsiSensePhysical            = 0x00001000,                    /* Autosense buffer ptr is physical            */
  837.     scsiFlagReserved5            = 0x00000800,                    /*                                          */
  838.     scsiFlagReserved6            = 0x00000400,                    /*                                             */
  839.     scsiFlagReserved7            = 0x00000200,                    /*                                             */
  840.     scsiFlagReserved8            = 0x00000100                    /*                                             */
  841. };
  842.  
  843. /* bit masks for the scsiIOFlags field in SCSIExecIOPB */
  844. enum {
  845.     scsiNoParityCheck            = 0x0002,                        /* disable parity checking                             */
  846.     scsiDisableSelectWAtn        = 0x0004,                        /* disable select w/Atn                              */
  847.     scsiSavePtrOnDisconnect        = 0x0008,                        /* do SaveDataPointer upon Disconnect msg             */
  848.     scsiNoBucketIn                = 0x0010,                        /* don’t bit bucket in during this I/O                 */
  849.     scsiNoBucketOut                = 0x0020,                        /* don’t bit bucket out during this I/O             */
  850.     scsiDisableWide                = 0x0040,                        /* disable wide transfer negotiation                 */
  851.     scsiInitiateWide            = 0x0080,                        /* initiate wide transfer negotiation                 */
  852.     scsiRenegotiateSense        = 0x0100,                        /* renegotiate sync/wide before issuing autosense     */
  853.     scsiDisableDiscipline        = 0x0200,                        /* disable parameter checking on SCSIExecIO calls    */
  854.     scsiIOFlagReserved0080        = 0x0080,                        /*                                                  */
  855.     scsiIOFlagReserved8000        = 0x8000                        /*                                                     */
  856. };
  857.  
  858. /* Defines for the SIM/HBA queue actions.  These values are used in the */
  859. /* SCSIExecIOPB, for the queue action field. [These values should match the */
  860. /* defines from some other include file for the SCSI message phases.  We may */
  861. /* not need these definitions here. ] */
  862. enum {
  863.     scsiSimpleQTag                = 0x20,                            /* Tag for a simple queue                                 */
  864.     scsiHeadQTag                = 0x21,                            /* Tag for head of queue                                  */
  865.     scsiOrderedQTag                = 0x22                            /* Tag for ordered queue                                 */
  866. };
  867.  
  868. /* Defines for the Bus Inquiry PB fields. */
  869. /* scsiHBAInquiry field bits */
  870. enum {
  871.     scsiBusMDP                    = 0x80,                            /* Supports Modify Data Pointer message                        */
  872.     scsiBusWide32                = 0x40,                            /* Supports 32 bit wide SCSI                                */
  873.     scsiBusWide16                = 0x20,                            /* Supports 16 bit wide SCSI                                */
  874.     scsiBusSDTR                    = 0x10,                            /* Supports Sync Data Transfer Req message                    */
  875.     scsiBusLinkedCDB            = 0x08,                            /* Supports linked CDBs                                        */
  876.     scsiBusTagQ                    = 0x02,                            /* Supports tag queue message                                */
  877.     scsiBusSoftReset            = 0x01                            /* Supports soft reset                                        */
  878. };
  879.  
  880. /* scsiDataTypes field bits  */
  881. /*    bits 0->15 Apple-defined, 16->30 3rd-party unique, 31 = reserved */
  882. enum {
  883.     scsiBusDataTIB                = (1 << scsiDataTIB),            /* TIB supplied (ptr in scsiDataPtr)        */
  884.     scsiBusDataBuffer            = (1 << scsiDataBuffer),        /* single contiguous buffer supplied         */
  885.     scsiBusDataSG                = (1 << scsiDataSG),            /* scatter/gather list supplied             */
  886.     scsiBusDataReserved            = 0x80000000                    /*                                           */
  887. };
  888.  
  889. /* scsiScanFlags field bits */
  890. enum {
  891.     scsiBusScansDevices            = 0x80,                            /* Bus scans for and maintains device list            */
  892.     scsiBusScansOnInit            = 0x40,                            /* Bus scans performed at power-up/reboot            */
  893.     scsiBusLoadsROMDrivers        = 0x20                            /* may load ROM drivers to support targets             */
  894. };
  895.  
  896. /* scsiFeatureFlags field bits */
  897. enum {
  898.     scsiBusInternalExternalMask    = 0x000000C0,                    /* bus internal/external mask                    */
  899.     scsiBusInternalExternalUnknown = 0x00000000,                /* not known whether bus is inside or outside     */
  900.     scsiBusInternalExternal        = 0x000000C0,                    /* bus goes inside and outside the box             */
  901.     scsiBusInternal                = 0x00000080,                    /* bus goes inside the box                         */
  902.     scsiBusExternal                = 0x00000040,                    /* bus goes outside the box                     */
  903.     scsiBusCacheCoherentDMA        = 0x00000020,                    /* DMA is cache coherent                         */
  904.     scsiBusOldCallCapable        = 0x00000010,                    /* SIM is old call capable                         */
  905.     scsiBusDifferential            = 0x00000004,                    /* Single Ended (0) or Differential (1)         */
  906.     scsiBusFastSCSI                = 0x00000002,                    /* HBA supports fast SCSI                         */
  907.     scsiBusDMAavailable            = 0x00000001                    /* DMA is available                             */
  908. };
  909.  
  910. /* scsiWeirdStuff field bits */
  911. enum {
  912.     scsiOddDisconnectUnsafeRead1 = 0x0001,                        /* Disconnects on odd byte boundries are unsafe with DMA and/or blind reads */
  913.     scsiOddDisconnectUnsafeWrite1 = 0x0002,                        /* Disconnects on odd byte boundries are unsafe with DMA and/or blind writes */
  914.     scsiBusErrorsUnsafe            = 0x0004,                        /* Non-handshaked delays or disconnects during blind transfers may cause a crash */
  915.     scsiRequiresHandshake        = 0x0008,                        /* Non-handshaked delays or disconnects during blind transfers may cause data corruption */
  916.     scsiTargetDrivenSDTRSafe    = 0x0010                        /* Targets which initiate synchronous negotiations are supported */
  917. };
  918.  
  919. /* scsiHBAslotType values */
  920. enum {
  921.     scsiMotherboardBus            = 0x01,                            /* A built in Apple supplied bus                     */
  922.     scsiNuBus                    = 0x02,                            /* A SIM on a NuBus card                             */
  923.     scsiPDSBus                    = 0x03,                            /*    "  on a PDS card                                */
  924.     scsiPCIBus                    = 0x04,                            /*    "  on a PCI bus card                            */
  925.     scsiPCMCIABus                = 0x05,                            /*    "  on a PCMCIA card                            */
  926.     scsiFireWireBridgeBus        = 0x06                            /*    "  connected through a FireWire bridge        */
  927. };
  928.  
  929. /* Defines for the scsiDriverFlags field (in SCSIDriverPB) */
  930. enum {
  931.     scsiDeviceSensitive            = 0x0001,                        /* Only driver should access this device                */
  932.     scsiDeviceNoOldCallAccess    = 0x0002                        /* no old call access to this device                     */
  933. };
  934.  
  935. /*  SIMInitInfo PB */
  936. /* directions are for SCSIRegisterBus call ( -> parm, <- result)             */
  937. struct SIMInitInfo {
  938.     UInt8                            *SIMstaticPtr;                /* <- alloc. ptr to the SIM's static vars                 */
  939.     long                            staticSize;                    /* -> num bytes SIM needs for static vars                 */
  940.     SIMInitUPP                        SIMInit;                    /* -> pointer to the SIM init routine                     */
  941.     SIMActionUPP                    SIMAction;                    /* -> pointer to the SIM action routine                 */
  942.     SCSIInterruptUPP                SIM_ISR;                    /*       reserved                                             */
  943.     SCSIInterruptUPP                SIMInterruptPoll;            /* -> pointer to the SIM interrupt poll routine            */
  944.     SIMActionUPP                    NewOldCall;                    /* -> pointer to the SIM NewOldCall routine                */
  945.     UInt16                            ioPBSize;                    /* -> size of SCSI_IO_PBs required for this SIM            */
  946.     Boolean                            oldCallCapable;                /* -> true if this SIM can handle old-API calls            */
  947.     UInt8                            simInfoUnused1;                /*       reserved                                            */
  948.     long                            simInternalUse;                /* xx not affected or viewed by XPT                        */
  949.     SCSIUPP                            XPT_ISR;                    /*    reserved                                            */
  950.     SCSIUPP                            EnteringSIM;                /* <- ptr to the EnteringSIM routine                    */
  951.     SCSIUPP                            ExitingSIM;                    /* <- ptr to the ExitingSIM routine                        */
  952.     SCSIMakeCallbackUPP                MakeCallback;                /* <- the XPT layer’s SCSIMakeCallback routine            */
  953.     UInt16                            busID;                        /* <- bus number for the registered bus                    */
  954.     UInt16                            simInfoUnused3;                /* <- reserved                                            */
  955.     long                            simInfoUnused4;                /* <- reserved                                            */
  956. };
  957. typedef struct SIMInitInfo SIMInitInfo;
  958.  
  959. /* Glue between SCSI calls and SCSITrap format */
  960.  
  961. enum {
  962.     xptSCSIAction                = 0x0001,
  963.     xptSCSIRegisterBus            = 0x0002,
  964.     xptSCSIDeregisterBus        = 0x0003,
  965.     xptSCSIReregisterBus        = 0x0004,
  966.     xptSCSIKillXPT                = 0x0005,                        /* kills Mini-XPT after transition */
  967.     xptSCSIInitialize            = 0x000A                        /* Initialize the SCSI manager */
  968. };
  969.  
  970. /* SCSI status*/
  971. enum {
  972.     scsiStatGood                = 0x00,                            /* Good Status*/
  973.     scsiStatCheckCondition        = 0x02,                            /* Check Condition*/
  974.     scsiStatConditionMet        = 0x04,                            /* Condition Met*/
  975.     scsiStatBusy                = 0x08,                            /* Busy*/
  976.     scsiStatIntermediate        = 0x10,                            /* Intermediate*/
  977.     scsiStatIntermedMet            = 0x14,                            /* Intermediate - Condition Met*/
  978.     scsiStatResvConflict        = 0x18,                            /* Reservation conflict*/
  979.     scsiStatTerminated            = 0x20,                            /* Command terminated*/
  980.     scsiStatQFull                = 0x28                            /* Queue full*/
  981. };
  982.  
  983. /* SCSI messages*/
  984. enum {
  985.     kCmdCompleteMsg                = 0,
  986.     kExtendedMsg,                                                /* 0x01*/
  987.     kSaveDataPointerMsg,                                        /* 0x02*/
  988.     kRestorePointersMsg,                                        /* 0x03*/
  989.     kDisconnectMsg,                                                /* 0x04*/
  990.     kInitiatorDetectedErrorMsg,                                    /* 0x05*/
  991.     kAbortMsg,                                                    /* 0x06*/
  992.     kMsgRejectMsg,                                                /* 0x07*/
  993.     kNoOperationMsg,                                            /* 0x08*/
  994.     kMsgParityErrorMsg,                                            /* 0x09*/
  995.     kLinkedCmdCompleteMsg,                                        /* 0x0a*/
  996.     kLinkedCmdCompleteWithFlagMsg,                                /* 0x0b*/
  997.     kBusDeviceResetMsg,                                            /* 0x0c*/
  998.     kAbortTagMsg,                                                /* 0x0d*/
  999.     kClearQueueMsg,                                                /* 0x0e*/
  1000.     kInitiateRecoveryMsg,                                        /* 0x0f*/
  1001.     kReleaseRecoveryMsg,                                        /* 0x10*/
  1002.     kTerminateIOProcessMsg,                                        /* 0x11*/
  1003.     kSimpleQueueTag                = 0x20,                            /* 0x20*/
  1004.     kHeadOfQueueTagMsg,                                            /* 0x21*/
  1005.     kOrderedQueueTagMsg,                                        /* 0x22*/
  1006.     kIgnoreWideResidueMsg                                        /* 0x23*/
  1007. };
  1008.  
  1009. /* moveq #kSCSIx, D0;  _SCSIAtomic */
  1010.  
  1011. #if !GENERATINGCFM
  1012. #pragma parameter __D0 SCSIAction(__A0)
  1013. #endif
  1014. extern pascal OSErr SCSIAction(SCSI_PB *parameterBlock)
  1015.  TWOWORDINLINE(0x7001, 0xA089);
  1016.  
  1017. #if !GENERATINGCFM
  1018. #pragma parameter __D0 SCSIRegisterBus(__A0)
  1019. #endif
  1020. extern pascal OSErr SCSIRegisterBus(SIMInitInfo *parameterBlock)
  1021.  TWOWORDINLINE(0x7002, 0xA089);
  1022.  
  1023. #if !GENERATINGCFM
  1024. #pragma parameter __D0 SCSIDeregisterBus(__A0)
  1025. #endif
  1026. extern pascal OSErr SCSIDeregisterBus(SCSI_PB *parameterBlock)
  1027.  TWOWORDINLINE(0x7003, 0xA089);
  1028.  
  1029. #if !GENERATINGCFM
  1030. #pragma parameter __D0 SCSIReregisterBus(__A0)
  1031. #endif
  1032. extern pascal OSErr SCSIReregisterBus(SIMInitInfo *parameterBlock)
  1033.  TWOWORDINLINE(0x7004, 0xA089);
  1034.  
  1035. #if !GENERATINGCFM
  1036. #pragma parameter __D0 SCSIKillXPT(__A0)
  1037. #endif
  1038. extern pascal OSErr SCSIKillXPT(SIMInitInfo *parameterBlock)
  1039.  TWOWORDINLINE(0x7005, 0xA089);
  1040.  
  1041. #if PRAGMA_IMPORT_SUPPORTED
  1042. #pragma import off
  1043. #endif
  1044.  
  1045. #if PRAGMA_ALIGN_SUPPORTED
  1046. #pragma options align=reset
  1047. #endif
  1048.  
  1049. #ifdef __cplusplus
  1050. }
  1051. #endif
  1052.  
  1053. #endif /* __SCSI__ */
  1054.